const formatNum = {
  formatFn (s) {
    var t = ''
    s = s + ''
    var l = s.split('').reverse()
    var len = (s.indexOf('-') !== -1) ? l.length - 1 : l.length
    for (var i = 0; i < len; i++) {
      t += l[i] + ((i + 1) % 3 === 0 && (i + 1) !== len ? ',' : '')
    }
    return ((s.indexOf('-') !== -1) ? '-' : '') + t.split('').reverse().join('')
  },
  formatFnD (s) {
    var t = ''
    s = s + ''
    var l = s.split('').reverse()
    var len = (s.indexOf('-') !== -1) ? l.length - 1 : l.length
    for (var i = 0; i < len; i++) {
      t += l[i] + ((i + 1) % 3 === 0 && (i + 1) !== len ? ',' : '')
    }
    if (parseInt(s) === 0) {
      return s
    } else {
      return ((s.indexOf('-') !== -1) ? '' : '-') + t.split('').reverse().join('')
    }
  },
  decToHex (str) {
    var res = []
    for (var i = 0; i < str.length; i++) {
      res[i] = ('00' + str.charCodeAt(i).toString(16)).slice(-4)
    }
    return '\\u' + res.join('\\u')
  },
  hexToDec (str) {
    str = str.replace(/\\/g, '%')
    return unescape(str)
  }
}
export default formatNum
